package com.ctosb.classviewer.clazz.attr;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.AbstractParse;
import com.ctosb.classviewer.clazz.cp.CONSTANT_Utf8_info;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Local_variable_type_table extends AbstractParse {

    private short start_pc;
    private short length;
    private short name_index;
    private short signature_index;
    private short index;

    @Override
    public Local_variable_type_table parse(ClassReader classReader) {
        this.start_pc = classReader.readShort();
        this.length = classReader.readShort();
        this.name_index = classReader.readShort();
        this.signature_index = classReader.readShort();
        this.index = classReader.readShort();
        return this;
    }

    /**
     * 表示一个局部变量的有效的非全限定名
     * @Author alan
     * @Date 2020/12/16 12:25 上午
     * @return
     */
    public String getName() {
        return ((CONSTANT_Utf8_info) getClassFile().getConstant_pool()[name_index]).getValue();
    }

    /**
     * 表示给源程序中局部变量类型的字段签名
     * @Author alan
     * @Date 2020/12/16 12:24 上午
     * @return
     */
    public String getSignature() {
        return ((CONSTANT_Utf8_info) getClassFile().getConstant_pool()[signature_index]).getValue();
    }
}
